const common = {
  sq: function (imageUrl) {
    var that = this
    wx.showModal({
      title: '提示',
      content: '保存图片到本地',
      success: function (res) {
        if (res.confirm) {
          that.downloadImage(imageUrl);
        }
      }
    })
  },
  downloadImage: function (imageUrl) {
    var that = this
    wx.downloadFile({
      url: imageUrl, // 仅为示例，并非真实的资源
      success(res) {
        // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
        if (res.statusCode === 200) {
          that.saveLocalImage(res.tempFilePath)
        }
      }
    })
  },
  saveLocalImage: function (filepath) {
    wx.saveImageToPhotosAlbum({
      filePath: filepath,
      success(res) {
        wx.showToast({
          title: '保存成功',
        })
      }
    })
  }
}


export default common